﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class HeroFightDef
{
    public const int c_iSpineBaseOrder = 0;
    public const int c_iSpineActionOrder = 10;

    public const int c_iMaxHero = 6;

    public static Vector3 s_v3Left = new Vector3(-2,0.3f,0);
    public static Vector3 s_v3Right = new Vector3(2, 0.3f, 0);
    public const float c_fSpace = 2.5f;
    public const float c_fIgnoreOffset = 0.5f;

    public const string c_sAction_FIdle = "fidle";//待机
    public const string c_sAction_Idle = "idle";//没用
    public const string c_sAction_Hit = "hit";//受击
    public const string c_sAction_Attack = "skill0";//攻击 动作 1(现在是视屏里的挥刀砍,如果是远程则是拉弓射箭)
    public const string c_sAction_Run = "move";//移动
    public const string c_sAction_Move = "walk";//没用到
    public const string c_sAction_Dead = "lose";//死亡
    public const string c_sAction_Weak = "weak";// 虚弱待机
    public const string c_sAction_Win = "win";//胜利
    

    /// <summary>
    /// 跑过去砍一刀回来
    /// </summary>
    public const int c_iActionSkillType_0 = 0;
    /// <summary>
    /// 原地放子弹,子弹会飞过去
    /// </summary>
    public const int c_iActionSkillType_1 = 1;
    /// <summary>
    /// 原地施法,对方立即受击
    /// </summary>
    public const int c_iActionSkillType_2 = 2;
    /// <summary>
    /// 群體 
    /// </summary>
    public const int c_iActionSkillType_3 = 3;


    //多少血量百分比以下是重伤状态
    public const float c_fSerious = 0.6f;

    //编辑器用到的反击节点开始位置
    public const int c_iEditorFanJiNodeStart = 6000;

    
    //目标死亡或者受击动作播完之后过 X 秒结束这一回合
    public const float c_fRoundRest = 1;
    //BUF 结算回合,特效播放后X秒结束
    public const float c_fBufRest = 2;
    public const float c_fBufCheck = 0.5f;

    //保护的时候 啥时候跑过去, 最大的跑过去时间
    public const float c_fProtectMinMoveTime = 0.5f;

    //受击来源 Dmg
    public const int c_iHitType_Dmg = 1;
    //受击来源 BufDmg
    public const int c_iHitType_BufDmg = 2;
}

public class HeroFightUtil
{
    //第一套站位规则 从中间往2遍散开
    public static Vector3 GetPosByIndex(int index)
    {
        Vector3 result = Vector3.zero;
        bool left = index < SlgFightDef.c_iHeroIndexStep;
        index = index % SlgFightDef.c_iHeroIndexStep;
        if (left)
        {
            result = HeroFightDef.s_v3Left + new Vector3(-index * HeroFightDef.c_fSpace, 0, 0);
        }
        else
        {
            result = HeroFightDef.s_v3Right + new Vector3(index* HeroFightDef.c_fSpace, 0, 0);
        }

        return result;
    }

    public static Vector3 GetHeroPosByIndex(int index)
    {
        Vector3 result = Vector3.zero;
        for (int i = 0; i < HeroBattleMgr.Instance.m_LisHeros.Count; i++)
        {
            if(HeroBattleMgr.Instance.m_LisHeros[i].m_pHeroVo.index == index)
            {
                result = HeroBattleMgr.Instance.m_LisHeros[i].m_pGameObj.transform.position;
            }
        }
        return result;
    }

    public static Vector3 GetDir(int my,int target)
    {
        return (my < target) ? Vector3.right : Vector3.left;
    }

    public static void FlashWhiteScreen(int index,float duration)
    {
        SceneFadeInOut screenFlash = GameMain.SceneFadeInOutTool;
        if(screenFlash == null)
        {
            screenFlash = DriverInfo.SingletonObj.GetComponent<SceneFadeInOut>();
        }
        if(screenFlash != null)
        {
            screenFlash.FlashWhiteScreen(index, duration,HeroBattleMgr.Instance.Speed);
        }
    }

    public static void NormalHit()
    {
        FlashWhiteScreen(0, 1f);
    }

    public static void SetSpineOrderState(string state,BattleEntityHero hero)
    {
        switch (state)
        {
            case BattleHeroState.c_sMState_Hit:
                hero.m_pRender.sortingOrder = HeroFightDef.c_iSpineActionOrder + 1;
                break;
            case BattleHeroState.c_sMState_Action:
                hero.m_pRender.sortingOrder = HeroFightDef.c_iSpineActionOrder + 2;
                break;
            case BattleHeroState.c_sMState_Move:
                hero.m_pRender.sortingOrder = HeroFightDef.c_iSpineActionOrder + 3;
                break;
            case BattleHeroState.c_sMState_Dead:
                hero.m_pRender.sortingOrder = HeroFightDef.c_iSpineActionOrder + 4;
                break;
            case BattleHeroState.c_sMState_Win:
                hero.m_pRender.sortingOrder = HeroFightDef.c_iSpineActionOrder + 5;
                break;
        }
    }
}


public class SlgFightDef
{
    public const string c_strEffPoolName = "Effect";

    public const int c_iMaxUnitNum = 40;

    public const int c_iFrameLoadObjNum = 10;

    public const int c_iHeroEffType_Trooo = 1;
    public const int c_iHeroEffType_Unit = 2;

    //slg站位相关
    public const int c_iHeroIndexStep = 20;

    //3D小兵的动作
    public const string c_sModelAction_Walk = "walk";
    public const string c_sModelAction_A1 = "a1";
    public const string c_sModelAction_A2 = "a2";
    public const string c_sModelAction_Die = "die";
    public const string c_sModelAction_Hurt = "hurt";
    public const string c_sModelAction_Idle = "idle";
    public const string c_sModelAction_Run = "run";
    public const string c_sModelAction_S1 = "s1";

    //SLG小兵的行为
    public const string c_sAction_Move = "move";
    public const string c_sAction_A1 = "attack";
    public const string c_sAction_A2 = "shoot";
    public const string c_sAction_Skill = "skill";
    public const string c_sAction_Dead = "dead";
    public const string c_sAction_Idle = "idle";

    //solider 兵种类型
    public const int c_iArmyType_batman = 1;
    public const int c_iArmyType_Arrow = 2;
    public const int c_iArmyType_Knight = 3;
    public const int c_iArmyType_Tank = 4;

    private const float c_fStartBetweenHero = 2f;
    //冲锋的兵跑到距离英雄 X米之后往回跑
    public const float c_fChargeStopGapHero = -5f;
    //往回跑 X秒后进入结束
    public const float c_fRetreatDelay = 2f;
    /// <summary>
    /// 剑雨弓箭手射几波
    /// </summary>
    public const int c_iArrowShootNum = 2;
    /// <summary>
    /// 剑雨弓箭手射 一波间隔
    /// </summary>
    public const float c_fArrowShootGap = 0.8f;
    /// <summary>
    /// 剑雨落下来多少根
    /// </summary>
    public const int c_iArrowShootDownNum = 50;
    public static Vector3 vec3_LeftCenter = new Vector3(-20, 0, -1.5f);
    public static Vector3 vec3_RightCenter = new Vector3(20, 0, -1.5f);
    public const float m_fTroopWidth = 5.5f;
    public const float m_fTroopGrpHero = 4.5f;
    public const float m_fHeroHeight = 1;
    public static Vector3 CameraPos = new Vector3(0, 2.0f, -6.0f);
    private static Vector3 CameraAngle = new Vector3(20.0f, 0, 0);
    private static float CameraUpDis = 0f;
    private const float c_fUpCameraDuration = 2;
    private static float CameraDownDis = 0f;
    private const float c_fDownCameraDuration = 2;
    private const float c_fChargeBtweenShooter = 2;
    public const float c_fCameraMoveSpeed01 = 4;
    public const float c_fCameraMoveSpeed02 = 120;
    public const float c_fCameraMoveSpeed03 = 160;
    public const float c_fLeft2RightRest = 1;
    private const float c_fUIDuration = 1;
    private static float m_fArrowRainGap = 1;
    private static float m_fHeroSize = 0.5f;
    private static float m_fChargeAccMin = 3.0f;
    private static float m_fChargeAccMax = 4.1f;
    private static float m_fChangeSpeedMax = 7.0f;
    private static float m_fCrashSpeedMax = 7f;
    private static float m_fDeadGapMin = 0;
    private static float m_fDeadGapMax = 0.6f;
    public static float m_fDead_Time = 3.5f;
    public static float m_fDead_MinH = 1;
    public static float m_fDead_MaxH = 3f;
    public static float m_fDead_MinX = 2f;
    public static float m_fDead_MaxX = 3f;
    public static float m_fDead_MinZ = 2f;
    public static float m_fDead_MaxZ = 3f;
    public static string m_sDead_Path = "456";
    public static int m_iDeadToCameraNum = 3;
    public static float m_fDmgOffSet = 6;
    public static float m_fMaxFlyHeight = 2.5f;
    public static float m_fMinFlyHeight = 2.0f;
    public static float c_fFirstArrowShootDelayDmg = 0.5f;
    public static float c_fDelayArrow = 1;
    public static float c_fDelayCloseMainCamera = 1;
    public static float m_fFreshScreenDuration = 1;
    public static float m_fFreshScreenDelayMoveCamera = 0.6f;
    public static float c_fCameraShoot2BattleMan = 5;
    public static float c_fBattleManAhearMoveTime = 1;
    public static float c_fCameraWaitLeft = 1.5f;

    public static float FCameraWaitLeft
    {
        get
        {
            return (SlgBattleMgr.Instance.m_bEditorProp ? SlgBattleProperty.Instance.c_fCameraWaitLeft : c_fCameraWaitLeft);
        }
    }

    public static float FBattleManAhearMoveTime
    {
        get
        {
            return (SlgBattleMgr.Instance.m_bEditorProp ? SlgBattleProperty.Instance.c_fBattleManAhearMoveTime : c_fBattleManAhearMoveTime);
        }
    }
    public static float FCameraShoot2BattleMan
    {
        get
        {
            return (SlgBattleMgr.Instance.m_bEditorProp ? SlgBattleProperty.Instance.c_fCameraShoot2BattleMan : c_fCameraShoot2BattleMan);
        }
    }

    public static float FDownCameraDuration
    {
        get
        {
            return (SlgBattleMgr.Instance.m_bEditorProp ? SlgBattleProperty.Instance.c_fDownCameraDuration : c_fDownCameraDuration);
        }
    }
    public static float FCameraDownDis
    {
        get
        {
            return (SlgBattleMgr.Instance.m_bEditorProp ? SlgBattleProperty.Instance.CameraDownDis : CameraDownDis);
        }
    }
    public static float FChargeBtweenShooter
    {
        get
        {
            return (SlgBattleMgr.Instance.m_bEditorProp ? SlgBattleProperty.Instance.c_fChargeBtweenShooter : c_fChargeBtweenShooter);
        }
    }
    public static string SDead_Path
    {
        get
        {
            return (SlgBattleMgr.Instance.m_bEditorProp ? SlgBattleProperty.Instance.m_sDead_Path : m_sDead_Path);
        }
         
    }
    public static float FFreshScreenDuration
    {
        get
        {
            return (SlgBattleMgr.Instance.m_bEditorProp ? SlgBattleProperty.Instance.m_fFreshScreenDuration : m_fFreshScreenDuration);
        }
    }
    public static float FFreshScreenDelayMoveCamera
    {
        get
        {
            return (SlgBattleMgr.Instance.m_bEditorProp ? SlgBattleProperty.Instance.m_fFreshScreenDelayMoveCamera : m_fFreshScreenDelayMoveCamera);
        }
    }
    public static float FDelayCloseMainCamera
    {
        get
        {
            return (SlgBattleMgr.Instance.m_bEditorProp ? SlgBattleProperty.Instance.c_fDelayCloseMainCamera : c_fDelayCloseMainCamera);
        }
    }
    public static float FDelayArrow
    {
        get
        {
            return (SlgBattleMgr.Instance.m_bEditorProp ? SlgBattleProperty.Instance.c_fDelayArrow : c_fDelayArrow);
        }
    }
    public static float FMaxFlyHeight
    {
        get
        {
            return (SlgBattleMgr.Instance.m_bEditorProp ? SlgBattleProperty.Instance.m_fMaxFlyHeight : m_fMaxFlyHeight);
        }
    }
    public static float FMinFlyHeight
    {
        get
        {
            return (SlgBattleMgr.Instance.m_bEditorProp ? SlgBattleProperty.Instance.m_fMinFlyHeight : m_fMinFlyHeight);
        }
    }
    public static float FFirstArrowShootDelayDmg
    {
        get
        {
            return (SlgBattleMgr.Instance.m_bEditorProp ? SlgBattleProperty.Instance.c_fFirstArrowShootDelayDmg : c_fFirstArrowShootDelayDmg);
        }
    }
    public static float FDead_Time
    {
        get
        {
            return (SlgBattleMgr.Instance.m_bEditorProp ? SlgBattleProperty.Instance.m_fDead_Time : m_fDead_Time);
        }
    }
    //public static float FDead_MinH
    //{
    //    get
    //    {
    //        return (SlgBattleMgr.Instance.m_bEditorProp ? SlgBattleProperty.Instance.m_fDead_MinH : m_fDead_MinH);
    //    }
    //}
    //public static float FDead_MaxH
    //{
    //    get
    //    {
    //        return (SlgBattleMgr.Instance.m_bEditorProp ? SlgBattleProperty.Instance.m_fDead_MaxH : m_fDead_MaxH);
    //    }
    //}
    //public static float FDead_MinX
    //{
    //    get
    //    {
    //        return (SlgBattleMgr.Instance.m_bEditorProp ? SlgBattleProperty.Instance.m_fDead_MinX : m_fDead_MinX);
    //    }
    //}
    //public static float FDead_MaxX
    //{
    //    get
    //    {
    //        return (SlgBattleMgr.Instance.m_bEditorProp ? SlgBattleProperty.Instance.m_fDead_MaxX : m_fDead_MaxX);
    //    }
    //}
    //public static float FDead_MinZ
    //{
    //    get
    //    {
    //        return (SlgBattleMgr.Instance.m_bEditorProp ? SlgBattleProperty.Instance.m_fDead_MinZ : m_fDead_MinZ);
    //    }
    //}
    //public static float FDead_MaxZ
    //{
    //    get
    //    {
    //        return (SlgBattleMgr.Instance.m_bEditorProp ? SlgBattleProperty.Instance.m_fDead_MaxZ : m_fDead_MaxZ);
    //    }
    //}
    public static float FStartBetweenHero
    {
        get
        {
            return (SlgBattleMgr.Instance.m_bEditorProp ? SlgBattleProperty.Instance.c_fStartBetweenHero : c_fStartBetweenHero);
        }
    }
    public static float FDmgOffSet
    {
        get
        {
            return (SlgBattleMgr.Instance.m_bEditorProp ? SlgBattleProperty.Instance.m_fDmgOffSet : m_fDmgOffSet);
        }
    }
    public static float FChargeStopGapHero
    {
        get
        {
            return (SlgBattleMgr.Instance.m_bEditorProp ? SlgBattleProperty.Instance.c_fChargeStopGapHero : c_fChargeStopGapHero);
        }
    }
    public static float FRetreatDelay
    {
        get
        {
            return (SlgBattleMgr.Instance.m_bEditorProp ? SlgBattleProperty.Instance.c_fRetreatDelay : c_fRetreatDelay);
        }
    }
    public static int IArrowShootNum
    {
        get
        {
            return (SlgBattleMgr.Instance.m_bEditorProp ? SlgBattleProperty.Instance.c_iArrowShootNum : c_iArrowShootNum);
        }
    }
    public static float FArrowShootGap
    {
        get
        {
            return (SlgBattleMgr.Instance.m_bEditorProp ? SlgBattleProperty.Instance.c_fArrowShootGap : c_fArrowShootGap);
        }
    }
    public static int IArrowShootDownNum
    {
        get
        {
            return (SlgBattleMgr.Instance.m_bEditorProp ? SlgBattleProperty.Instance.c_iArrowShootDownNum : c_iArrowShootDownNum);
        }
    }
    public static Vector3 Vec3_LeftCenter
    {
        get
        {
            return (SlgBattleMgr.Instance.m_bEditorProp ? SlgBattleProperty.Instance.vec3_LeftCenter : vec3_LeftCenter);
        }
    }
    public static Vector3 Vec3_RightCenter
    {
        get
        {
            return (SlgBattleMgr.Instance.m_bEditorProp ? SlgBattleProperty.Instance.vec3_RightCenter : vec3_RightCenter);
        }
    }
    public static float FTroopWidth
    {
        get
        {
            return (SlgBattleMgr.Instance.m_bEditorProp ? SlgBattleProperty.Instance.m_fTroopWidth : m_fTroopWidth);
        }
    }
    public static float FTroopGrpHero
    {
        get
        {
            return (SlgBattleMgr.Instance.m_bEditorProp ? SlgBattleProperty.Instance.m_fTroopGrpHero : m_fTroopGrpHero);
        }
    }
    public static float FHeroHeight
    {
        get
        {
            return (SlgBattleMgr.Instance.m_bEditorProp ? SlgBattleProperty.Instance.m_fHeroHeight : m_fHeroHeight);
        }
    }
    public static Vector3 FCameraPos
    {
        get
        {
            return (SlgBattleMgr.Instance.m_bEditorProp ? SlgBattleProperty.Instance.CameraPos : CameraPos);
        }

        set
        {
            if (SlgBattleMgr.Instance.m_bEditorProp)
            {
                SlgBattleProperty.Instance.CameraPos = value;
            }
            else
            {
                CameraPos = value;
            }
            Debug.Log(value);
        }
    }
    public static Vector3 FCameraAngle
    {
        get
        {
            return (SlgBattleMgr.Instance.m_bEditorProp ? SlgBattleProperty.Instance.CameraAngle : CameraAngle);
        }
    }
    public static float FCameraUpDis
    {
        get
        {
            return (SlgBattleMgr.Instance.m_bEditorProp ? SlgBattleProperty.Instance.CameraUpDis : CameraUpDis);
        }
    }
    public static float FUpCameraDuration
    {
        get
        {
            return (SlgBattleMgr.Instance.m_bEditorProp ? SlgBattleProperty.Instance.c_fUpCameraDuration : c_fUpCameraDuration);
        }
    }
    public static float FCameraMoveSpeed01
    {
        get
        {
            return (SlgBattleMgr.Instance.m_bEditorProp ? SlgBattleProperty.Instance.c_fCameraMoveSpeed01 : c_fCameraMoveSpeed01);
        }
    }
    public static float FCameraMoveSpeed02
    {
        get
        {
            return (SlgBattleMgr.Instance.m_bEditorProp ? SlgBattleProperty.Instance.c_fCameraMoveSpeed02 : c_fCameraMoveSpeed02);
        }
    }
    public static float FCameraMoveSpeed03
    {
        get
        {
            return (SlgBattleMgr.Instance.m_bEditorProp ? SlgBattleProperty.Instance.c_fCameraMoveSpeed03 : c_fCameraMoveSpeed03);
        }
    }
    public static float FLeft2RightRest
    {
        get
        {
            return (SlgBattleMgr.Instance.m_bEditorProp ? SlgBattleProperty.Instance.c_fLeft2RightRest : c_fLeft2RightRest);
        }
    }
    public static float FUIDuration
    {
        get
        {
            return (SlgBattleMgr.Instance.m_bEditorProp ? SlgBattleProperty.Instance.c_fUIDuration : c_fUIDuration);
        }
    }
    public static float FArrowRainGap
    {
        get
        {
            return (SlgBattleMgr.Instance.m_bEditorProp ? SlgBattleProperty.Instance.m_fArrowRainGap : m_fArrowRainGap);
        }
    }
    public static float FHeroSize
    {
        get
        {
            return (SlgBattleMgr.Instance.m_bEditorProp ? SlgBattleProperty.Instance.m_fHeroSize : m_fHeroSize);
        }
    }
    public static float FChargeAccMin
    {
        get
        {
            return (SlgBattleMgr.Instance.m_bEditorProp ? SlgBattleProperty.Instance.m_fChargeAccMin : m_fChargeAccMin);
        }
    }
    public static float FChargeAccMax
    {
        get
        {
            return (SlgBattleMgr.Instance.m_bEditorProp ? SlgBattleProperty.Instance.m_fChargeAccMax : m_fChargeAccMax);
        }
    }
    public static float FChangeSpeedMax
    {
        get
        {
            return (SlgBattleMgr.Instance.m_bEditorProp ? SlgBattleProperty.Instance.m_fChangeSpeedMax : m_fChangeSpeedMax);
        }
    }
    public static float FCrashSpeedMax
    {
        get
        {
            return (SlgBattleMgr.Instance.m_bEditorProp ? SlgBattleProperty.Instance.m_fCrashSpeedMax : m_fCrashSpeedMax);
        }
    }
    public static float FDeadGapMin
    {
        get
        {
            return (SlgBattleMgr.Instance.m_bEditorProp ? SlgBattleProperty.Instance.m_fDeadGapMin : m_fDeadGapMin);
        }
    }
    public static float FDeadGapMax
    {
        get
        {
            return (SlgBattleMgr.Instance.m_bEditorProp ? SlgBattleProperty.Instance.m_fDeadGapMax : m_fDeadGapMax);
        }
    }
    public static float IDeadToCameraNum
    {
        get
        {
            return (SlgBattleMgr.Instance.m_bEditorProp ? SlgBattleProperty.Instance.m_iDeadToCameraNum : m_iDeadToCameraNum);
        }
    }
}

public class SlgFightUtil
{
    private const float c_fRang = 6;
    private const float c_fStart = 24f;

    private static Dictionary<int, Vector3> dicHead = new Dictionary<int, Vector3>()
    {
        {1,new Vector3( -c_fStart - c_fRang * 2 ,0,-1.5f) }, {2,new Vector3(-c_fStart - c_fRang * 1,0,-1.5f) }, {3,new Vector3(-c_fStart,0,-1.5f) },
        {4,new Vector3( -c_fStart ,0,-1.5f) }, {5,new Vector3(-c_fStart - c_fRang * 1,0,-1.5f) }, {6,new Vector3(-c_fStart - c_fRang * 2,0,-1.5f) },
        {7,new Vector3(-c_fStart - c_fRang * 3,0,-1.5f) },

        {21,new Vector3(c_fStart,0,-1.5f) }, {22,new Vector3(c_fStart + c_fRang * 1,0,-1.5f) }, {23,new Vector3(c_fStart + c_fRang * 2,0,-1.5f) },
        { 24,new Vector3(c_fStart + c_fRang * 2, 0, -1.5f) }, { 25,new Vector3(c_fStart + c_fRang * 1, 0, -1.5f) }, { 26,new Vector3(c_fStart + c_fRang * 0, 0, -1.5f) },
        {27,new Vector3(c_fStart + c_fRang * 3,0,-1.5f) },
    };

    public static int ConvertStandPosByPos(int pos)
    {
        //Left: 1 - 2 - 3 - 4    Right: 4 - 3 - 2 - 1
        //Hero Up->down  1-2-3

        int result = pos;
        switch (pos)
        {
            case 4:         //步兵
                result = 4;
                break;
            case 5:         //骑兵
                result = 3;
                break;
            case 6:         //射手
                result = 2;
                break;
            case 7:         //坦克
                result = 1;
                break;
            case 24:        //步兵
                result = 4;
                break;
            case 25:        //骑兵
                result = 3;
                break;
            case 26:        //射手
                result = 2;
                break;
            case 27:        //坦克
                result = 1;
                break;
            case 1:
                result = 1;
                break;
            case 2:
                result = 2;
                break;
            case 3:
                result = 3;
                break;
            case 21:
                result = 1;
                break;
            case 22:
                result = 2;
                break;
            case 23:
                result = 3;
                break;
        }
        return result;
    }

    public static Dictionary<bool, float> s_DicStopPos = new Dictionary<bool, float>()
    {
        {true, 55 },
        {false,-55 }
    };

    public static Vector3 GetTroopHeroPos(int pos)
    {
        Vector3 offset = GetTroopHeadPos(pos);
        offset += new Vector3(0, 0, 3);
        return offset;
    }

    public static Vector3 GetTroopHeadPos(int pos)
    {
        if (dicHead.ContainsKey(pos))
        {
            return dicHead[pos];
        }
        return Vector3.zero;
    }

    public static Vector3 GetTroopFormation(int formationId,int troopAllNum ,int index,bool left)
    {
        Vector3 result = Vector3.zero;
        FormationVo vo = Assets.Script.Config.ConfigManager.Instance.troopFormationLoader.GetFormation(formationId,troopAllNum);
        if(vo != null)
        {
            if(index < vo.lisVe3Pos.Count)
            {
                result = new Vector3((float)vo.lisVe3Pos[index].x * (left ? 1 : -1), (float)vo.lisVe3Pos[index].y, (float)vo.lisVe3Pos[index].z);
            }
        }
        return result;
    }

    //相对于小队的阵型
    public static Vector3 GetCubPos(int index, bool left)
    {
        Vector3 result;
        float x = 0.5f;
        float y = 0.5f;
        int yNum = 8;
        bool b_ODD = (yNum % 2) != 0;

        int remain_y = index % yNum;
        float yOffset = 0;
        bool b_remain_odd = (remain_y % 2) != 0;
        if (b_ODD)
        {
            //竖排最大个数是奇数
            yOffset = b_remain_odd ? Mathf.CeilToInt(remain_y / 2) * y : -Mathf.CeilToInt(remain_y / 2) * y;
        }
        else
        {
            if (b_remain_odd)
            {
                yOffset = Mathf.FloorToInt(remain_y / 2) * y + y * 0.5f;
            }
            else
            {
                yOffset = -(Mathf.FloorToInt(remain_y / 2) * y + y * 0.5f);
            }
        }

        int round_x = index / yNum;
        float xOffset = round_x * (left ? -x : x);
        result = new Vector3(xOffset, 0, yOffset);
        return result;
    }

    public static Vector3 GetStopPos(bool m_bLeft)
    {
        if (m_bLeft)
        {
            return GetTroopHeadPos(26);
        }
        else
        {
            return GetTroopHeadPos(1);
        }
    }

    public static Vector3 GetShootTarget(SlgEntitySoldier soldier)
    {
        Vector3 result = Vector3.zero;
        result = soldier.m_pGameObj.transform.position + new Vector3(soldier.m_pVo.m_bleft ? 10 : -10, Random.Range(3f,3.5f), 0);

        return result;
    }

    public static void GetShootStart(bool bleft,Vector3 center,float randomX,float randomZ,ref Vector3 start,ref Vector3 end)
    {
        Vector3 result = center;
        result += new Vector3(Random.Range(-randomX, randomX), 0, Random.Range(-randomZ, randomZ));
        end = result;
        Vector3 upDir = new Vector3(bleft ? 1 : -1, 1, 0).normalized;
        float length = Random.Range(5f, 20f);
        result += length * upDir;
        start = result;
    }

    public static string SubPath2ObjName(string path)
    {
        return path.Substring(path.LastIndexOf('/') + 1, path.Length - (path.LastIndexOf('/') + 1));
    }

    public static Vector3 GetTroopHeadPos(List<int> allTroopPos,bool bLeft,int pos)
    {
        Vector3 result = Vector3.zero;
        // 左边开始 1,2,3,4,5
        int index = ConvertStandPosByPos(pos);
        int myIndex = 0;
        for (int i = 0; i < allTroopPos.Count; i++)
        {
            allTroopPos[i] = ConvertStandPosByPos(allTroopPos[i]);
            if (index > allTroopPos[i])
                myIndex++;
        }

        float x = 0;
        int allTroopNum = allTroopPos.Count;

        if (allTroopNum % 2 != 0)
        {
            //单数
            int middle = allTroopNum / 2 + 1;
            x = (myIndex - middle) * SlgFightDef.FTroopWidth * (bLeft ? 1 : -1);
        }
        else
        {
            //偶数
            float middle = allTroopNum / 2.0f;
            x = ((float)myIndex - middle) * SlgFightDef.FTroopWidth * (bLeft ? 1 : -1);

        }
        Vector3 start = bLeft ? SlgFightDef.Vec3_LeftCenter : SlgFightDef.Vec3_RightCenter;

        result = new Vector3(start.x + x, start.y, start.z);

        return result;
    }

    public static Vector3 GetHeroPos(List<int> allTroopPos, bool bLeft,List<int> allHero,int pos)
    {
        Vector3 result = Vector3.zero;
        int endTroopIndex = 99;
        int tempStandPos;
        for (int i = 0; i < allTroopPos.Count; i++)
        {
             tempStandPos = ConvertStandPosByPos(allTroopPos[i]);
            if (tempStandPos < endTroopIndex)
                endTroopIndex = allTroopPos[i];
        }
        result = GetTroopHeadPos(allTroopPos, bLeft, endTroopIndex);
        result.x = bLeft ? (result.x - (SlgFightDef.FTroopGrpHero)) : (result.x + (SlgFightDef.FTroopGrpHero));

        int heroPos = ConvertStandPosByPos(pos);
        int myHeroIndex = 0;
        float z;
        for (int i = 0; i < allHero.Count; i++)
        {
            tempStandPos = ConvertStandPosByPos(allHero[i]);
            if (tempStandPos < heroPos)
                myHeroIndex++;
        }
        if(allHero.Count % 2 == 0)
        {
            //偶数
            float middle = allHero.Count / 2.0f;
            z = (myHeroIndex - middle) * SlgFightDef.FHeroHeight;
        }
        else
        {
            //奇数
            myHeroIndex = ConvertStandPosByPos(pos);
            int middle = allHero.Count / 2 + 1;
            z = (myHeroIndex - middle) * SlgFightDef.FHeroHeight;
        }

        result.z = result.z + z;

        return result;
    }
}